package com.innovation.chengzhangriji;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.innovation.chengzhangriji.preferences.LoginInfo;
import com.innovation.chengzhangriji.service.CheckVersionService;
import com.innovation.chengzhangriji.service.DeleteTimelineService;
import com.innovation.chengzhangriji.service.DownloadTimelineResService;
import com.innovation.chengzhangriji.service.GetAllBabyInfoService;
import com.innovation.chengzhangriji.service.GetAllParentInfoService;
import com.innovation.chengzhangriji.service.LoadTimelineService;
import com.innovation.chengzhangriji.service.LocalCommentService;
import com.innovation.chengzhangriji.service.SyncConfigService;
import com.innovation.chengzhangriji.service.SyncLocalCommentService;
import com.innovation.chengzhangriji.service.SyncTimelineService;
import com.innovation.chengzhangriji.service.UploadTimelineService;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Config {

    /*服务器地址类型*/

    public static final int URL_DEV = 1;

    public static final int URL_TEST = 2;

    public static final int URL_OFFICIAL = 3;

    public static final int URL_YINGYONGBAO = 4;


    /*系统版本*/
    public static final String VERSION = "2.4.5";
    public static final int VERSION_CODE = 200405;

    /*资源类型*/
    public static final String AUDIO = "audios";
    public static final String VIDEO = "videos";

    /*发布渠道*/
    public static final String CHANNEL;

    static {
        switch (com.innovation.chengzhangriji.Flavors.URL_TYPE) {
            case URL_DEV:
                CHANNEL = null;
                break;
            case URL_TEST:
                CHANNEL = null;
                break;
            case URL_OFFICIAL:
                CHANNEL = null;
                break;
            case URL_YINGYONGBAO:
                CHANNEL = "应用宝";
                break;
            default:
                CHANNEL = null;
                break;
        }
    }


    /*页面名称,用于友盟统计*/

    /**
     * 欢迎页
     */
    public static final String UMENG_PAGE_WELCOME = "欢迎页";

    /**
     * 引导页
     */
    public static final String UMENG_PAGE_GUIDE = "引导页";

    /**
     * 注册页1
     */
    public static final String UMENG_PAGE_SIGN_1 = "注册页1";
    /**
     * 注册页2
     */
    public static final String UMENG_PAGE_SIGN_2 = "注册页2";
    /**
     * 注册页3
     */
    public static final String UMENG_PAGE_SIGN_3 = "注册页3";
    /**
     * 普通登录页
     */
    public static final String UMENG_PAGE_LOGIN_NORMAL = "普通登录页";
    /**
     * 动态登录页
     */
    public static final String UMENG_PAGE_LOGIN_DYNAMIC = "动态登录页";
    /**
     * 选择阶段
     */
    public static final String UMENG_PAGE_SELECT = "选择阶段";
    /**
     * 二维码采集
     */
    public static final String UMENG_PAGE_CAPTURE = "二维码采集";
    /**
     * 创建宝贝
     */
    public static final String UMENG_PAGE_CREATE = "创建宝贝";
    /**
     * 照相
     */
    public static final String UMENG_PAGE_CAMERA = "照相";
    /**
     * 头像选择相册
     */
    public static final String UMENG_PAGE_HEAD_PHOTO = "头像选择相册";
    /**
     * 时间轴
     */
    public static final String UMENG_PAGE_TIMELINE = "时间轴";
    /**
     * 时间轴相册
     */
    public static final String UMENG_PAGE_TIMELINE_PHOTO = "时间轴相册";
    /**
     * 时间轴相机
     */
    public static final String UMENG_PAGE_TIMELINE_CAMERA = "时间轴相机";
    /**
     * 历史照片
     */
    public static final String UMENG_PAGE_HISTORY_PHOTO = "历史照片";
    /**
     * 历史视频
     */
    public static final String UMENG_PAGE_HISTORY_VIDEO = "历史视频";

    /*字体地址*/

    /**
     * 字体地址
     */
    public static final String CUTE_FONTS = "fonts/yuppy_sc_regular.otf";

    /*数据库名称*/

    /**
     * 数据库名称
     */
    public static final String DB_NAME = "chzhrj-db";



    /*加密盐值*/

    /**
     * 加密盐值
     */
//    public static final String SALT;
//
//    /*微信*/
//
//    public static final String WX_APP_ID;
//
//    /*小米*/
//
//    public static final String MIPUSH_APP_ID;
//
//    public static final String MIPUSH_APP_KEY;

    public static final String CONFIG_FILE_NAME;

    public static final String AES_PASSWORD = "oY#\n*a@a*R2nGSc$";

    static {
        switch (com.innovation.chengzhangriji.Flavors.URL_TYPE) {
            case URL_DEV:
//                SALT = "HX^HtZSDXBZN[g5SV-f,yq926h)pj3mZ";
//                WX_APP_ID = "wx640e5cd24796ac14";
//                MIPUSH_APP_ID = "2882303761517406954";
//                MIPUSH_APP_KEY = "5391740670954";
                CONFIG_FILE_NAME = "dev.config";
                break;
            case URL_TEST:
//                SALT = "HX^HtZSDXBZN[g5SV-f,yq926h)pj3mZ";
//                WX_APP_ID = "wx3feb5ccedbd30c97";
//                MIPUSH_APP_ID = "2882303761517409379";
//                MIPUSH_APP_KEY = "5801740937379";
                CONFIG_FILE_NAME = "int.config";
                break;
            case URL_OFFICIAL:
//                SALT = "k%34.gEb6v[eUNt1E4K.KSpNt+xn~vzI";
//                WX_APP_ID = "wx8cf7134a5313fd54";
//                MIPUSH_APP_ID = "2882303761517415877";
//                MIPUSH_APP_KEY = "5471741519877";
                CONFIG_FILE_NAME = "vip.config";
                break;
            case URL_YINGYONGBAO:
//                SALT = "k%34.gEb6v[eUNt1E4K.KSpNt+xn~vzI";
//                WX_APP_ID = "wx855e725cc784aa91";
//                MIPUSH_APP_ID = "2882303761517415880";
//                MIPUSH_APP_KEY = "5311741552880";
                CONFIG_FILE_NAME = "official.config";
                break;
            default:
//                SALT = "k%34.gEb6v[eUNt1E4K.KSpNt+xn~vzI";
//                WX_APP_ID = "wx855e725cc784aa91";
//                MIPUSH_APP_ID = "";
//                MIPUSH_APP_KEY = "";
                CONFIG_FILE_NAME = "vip.config";
                break;
        }
    }

    // 获取配置文件
    public static String getConfig(String key) {
        return ConfigurationManager.getInstance().get(key);
    }

    /*长度*/

    /**
     * 查询长度
     */
    public static final int QUERY_LENGTH = 15;

    /*引导页信息*/

    /**
     * 引导页信息保存地址
     */
    public static final String PREF_GUIDE = "pref_guide";

    /**
     * 引导页信息编码
     * 1 对应发布版本 VERSION_CODE 1
     * 2 对应发布版本 VERSION_CODE 2
     */
    public static final String GUIDE_CODE = "1";

    /**
     * 设置引导页信息
     *
     * @param context 上下文
     * @param value   true 已展示 false 未展示
     */
    public static void setGuide(Context context, boolean value) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_GUIDE, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(Config.GUIDE_CODE, value).apply();
    }

    /**
     * 获得引导页信息
     *
     * @param context 上下
     * @return true 已展示 false 未展示
     */
    public static boolean getGuide(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_GUIDE, Context.MODE_PRIVATE);
        return preferences.getBoolean(Config.GUIDE_CODE, false);
    }

    /*注册成功发送广播*/

    /**
     * 注册成功
     */
    public static final String ACTION_SIGN_UP_SUCCESS = "com.innovation.chengzhangriji.intent.action.ACTION_SIGN_UP_SUCCESS";

    /**
     * 登录信息
     */
    public static final String ACTION_EXTERNAL_SIGN_UP_SUCCESS_LOGIN_INFO = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SIGN_UP_SUCCESS_LOGIN_INFO";

    /*登录信息*/

    /**
     * 登录信息保存地址
     */
    public static final String PREF_LOGIN = "pref_login";

    /**
     * 登录信息键
     */
    public static final String LOGIN_KEY = "login_key";

    /**
     * 设置登录信息
     */
    public static void setLoginInfo(Context context, String value) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_LOGIN, Context.MODE_PRIVATE);
        preferences.edit().putString(Config.LOGIN_KEY, value).apply();
    }

    /**
     * 获得登录信息
     */
    public static LoginInfo getLoginInfo(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_LOGIN, Context.MODE_PRIVATE);
        String value = preferences.getString(Config.LOGIN_KEY, "");
        if (!TextUtils.isEmpty(value)) {
            Gson gson = new Gson();
            return gson.fromJson(value, LoginInfo.class);
        }
        return null;
    }

    /**
     * 清空登录信息
     */
    public static void cleanLogin(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_LOGIN, Context.MODE_PRIVATE);
        preferences.edit().clear().apply();
        setMiPushIdSuccess(context, false);
        cleanHasNewMessage(context);
        cleanHasNewComment(context);
        stopAllService(context);
    }

    /*MiPushToken*/

    /**
     * MiPushToken保存地址
     */
    public static final String PREF_MI_PUSH = "pref_mi_push";

    /**
     * MiPushRegId键
     */
    public static final String MI_PUSH_KEY = "mi_push_key";

    /**
     * 上传到服务器成功
     */
    public static final String MI_PUSH_SUCCESS_KEY = "mi_push_succes_key";

    /**
     * 设置MiPushRegId
     */
    public static void setMiPushId(Context context, String regId) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_MI_PUSH, Context.MODE_PRIVATE);
        preferences.edit().putString(Config.MI_PUSH_KEY, regId).apply();
    }

    /**
     * 获取MiPushRegId
     */
    public static String getMiPushId(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_MI_PUSH, Context.MODE_PRIVATE);
        return preferences.getString(Config.MI_PUSH_KEY, "");
    }

    /**
     * 设置上传MiPushRegId是否成功
     */
    public static void setMiPushIdSuccess(Context context, boolean success) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_MI_PUSH, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(Config.MI_PUSH_SUCCESS_KEY, success).apply();
    }

    /**
     * 获取上传MiPushRegId是否成功
     */
    public static boolean getMiPushIdSuccess(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_MI_PUSH, Context.MODE_PRIVATE);
        return preferences.getBoolean(Config.MI_PUSH_SUCCESS_KEY, false);
    }

    /**
     * 有新日记圈消息
     */
    public static final String PREF_NEW_MESSAGE = "pref_new_message";

    /**
     * 有新日记圈消息键
     */
    public static final String NEW_MESSAGE_KEY = "new_message_key";

    /**
     * 设置是否有新日记圈消息
     */
    public static void setHasNewMessage(Context context, boolean hasNewMsg) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_MESSAGE, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(Config.NEW_MESSAGE_KEY, hasNewMsg).apply();
    }

    /**
     * 获取有新日记圈消息
     */
    public static boolean getHasNewMessage(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_MESSAGE, Context.MODE_PRIVATE);
        return preferences.getBoolean(Config.NEW_MESSAGE_KEY, false);
    }

    /**
     * 清空有新日记圈消息
     */
    public static void cleanHasNewMessage(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_MESSAGE, Context.MODE_PRIVATE);
        preferences.edit().clear().apply();
    }

    /**
     * 有新评论消息
     */
    public static final String PREF_NEW_COMMENT = "pref_new_comment";

    /**
     * 有新评论消息键
     */
    public static final String NEW_COMMENT_KEY = "new_comment_key";

    /**
     * 有新通知
     */
    public static final String PREF_NEW_NOTIFY = "new_notify_key";

    /**
     * 有新通知键
     */
    public static final String NEW_NOTIFY_KEY = "new_notify_key";

    /**
     * 日记数量
     */
    public static final String PREF_DIARY_COUNT = "pref_diary_count";

    public static final String DIARY_COUNT = "diary_count_key";
    public static final String TEXT_COUNT = "text_count_key";
    public static final String PHOTO_COUNT = "photo_count_key";
    public static final String AUDIO_COUNT = "audio_count_key";
    public static final String VIDEO_COUNT = "video_count_key";

    /**
     * 存储日记的照片，文本，语音，视频的数量
     * @param context
     * @param diaryCount
     * @param textCount
     * @param photoCount
     * @param audioCount
     * @param videoCount
     */
    public static void setDiaryCount(Context context, int diaryCount, int textCount, int photoCount, int audioCount, int videoCount) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_DIARY_COUNT, Context.MODE_PRIVATE);
        preferences.edit()
                .putInt(Config.DIARY_COUNT, diaryCount)
                .putInt(Config.TEXT_COUNT, textCount)
                .putInt(Config.PHOTO_COUNT, photoCount)
                .putInt(Config.AUDIO_COUNT, audioCount)
                .putInt(Config.VIDEO_COUNT, videoCount)
                .commit();
    }

    public static int getDiaryCount(Context context, String Key) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_DIARY_COUNT, Context.MODE_PRIVATE);
        return preferences.getInt(Key, 0);
    }

    /**
     * 设置是否有新评论消息
     */
    public static void setHasNewComment(Context context, boolean hasNewMsg) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_COMMENT, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(Config.NEW_COMMENT_KEY, hasNewMsg).apply();
    }

    /**
     * 获取有新评论消息
     */
    public static boolean getHasNewComment(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_COMMENT, Context.MODE_PRIVATE);
        return preferences.getBoolean(Config.NEW_COMMENT_KEY, false);
    }

    /**
     * 清空有新评论消息
     */
    public static void cleanHasNewComment(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_COMMENT, Context.MODE_PRIVATE);
        preferences.edit().clear().apply();
    }

    /**
     * 设置是否有新通知
     */
    public static void setHasNewNotify(Context context, boolean hasNewNotify) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_NOTIFY, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(Config.NEW_NOTIFY_KEY, hasNewNotify).apply();
    }

    /**
     * 获取有新通知
     */
    public static boolean getHasNewNotify(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_NOTIFY, Context.MODE_PRIVATE);
        return preferences.getBoolean(Config.NEW_NOTIFY_KEY, false);
    }

    /**
     * 清空有新评论消息
     */
    public static void cleanHasNewNotify(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(Config.PREF_NEW_NOTIFY, Context.MODE_PRIVATE);
        preferences.edit().clear().apply();
    }


    /**
     * 记录照片数量
     */
    public static void savePhotoNum(Context context, int value) {
        SharedPreferences preferences = context.getSharedPreferences("pref_photo_number", Context.MODE_PRIVATE);
        preferences.edit().putInt("photo_number", value).apply();
    }

    /**
     * 获得照片数量
     */
    public static int getPhotoNum(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("pref_photo_number", Context.MODE_PRIVATE);
        return preferences.getInt("photo_number", 0);
    }

    /**
     * 记录视频数量
     */
    public static void saveVideoNum(Context context, int value) {
        SharedPreferences preferences = context.getSharedPreferences("pref_video_number", Context.MODE_PRIVATE);
        preferences.edit().putInt("video_number", value).apply();
    }

    /**
     * 获得视频数量
     */
    public static int getVideoNum(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("pref_photo_number", Context.MODE_PRIVATE);
        return preferences.getInt("video_number", 0);
    }

    /*服务*/

    /**
     * 开启同步数据服务
     */
    public static void startSyncTimelineService(Context context) {
        Intent intent = new Intent(context, SyncTimelineService.class);
        context.startService(intent);
    }

    /**
     * 开启加载数据服务
     */
    public static void startLoadTimelineService(Context context) {
        Intent intent = new Intent(context, LoadTimelineService.class);
        context.startService(intent);
    }

    /**
     * 开启下载数据服务
     */
    public static void startDownloadTimelineService(Context context) {
        Intent intent = new Intent(context, DownloadTimelineResService.class);
        context.startService(intent);
    }

    /**
     * 开启上传数据服务
     */
    public static void startUploadTimelineService(Context context) {
        Intent intent = new Intent(context, UploadTimelineService.class);
        context.startService(intent);
    }

    /**
     * 开启删除数据服务
     */
    public static void startDeleteTimelineService(Context context) {
        Intent intent = new Intent(context, DeleteTimelineService.class);
        context.startService(intent);
    }

    /**
     * 开启同步离线评论服务
     */
    public static void startSyncLocalCommentService(Context context) {
        Intent intent = new Intent(context, SyncLocalCommentService.class);
        context.startService(intent);
    }

    /**
     * 开启检测升级服务
     */
    public static void startCheckVersionService(Context context) {
        Intent intent = new Intent(context, CheckVersionService.class);
        context.startService(intent);
    }

    /**
     * 开启获取所有宝贝信息服务
     */
    public static void startGetAllBabyInfoService(Context context) {
        Intent intent = new Intent(context, GetAllBabyInfoService.class);
        context.startService(intent);
    }

    /**
     * 开启获取所有宝贝关注人信息服务
     */
    public static void startGetAllParentInfoService(Context context) {
        Intent intent = new Intent(context, GetAllParentInfoService.class);
        context.startService(intent);
    }

    /**
     * 开启下载本地评论服务
     */
    public static void startLocalCommentService(Context context) {
        Intent intent = new Intent(context, LocalCommentService.class);
        context.startService(intent);
    }

    public static void startLocalCommentService(Context context, Bundle bundle) {
        Intent intent = new Intent(context, LocalCommentService.class);
        intent.putExtras(bundle);
        context.startService(intent);
    }

    /**
     * 开启同步配置服务
     */
    public static void startSyncConfigService(Context context) {
        Intent intent = new Intent(context, SyncConfigService.class);
        context.startService(intent);
    }

    /**
     * 停止所有服务
     */
    private static void stopAllService(Context context) {
        Intent intent = new Intent(context, SyncTimelineService.class);
        context.stopService(intent);
        Intent intent2 = new Intent(context, LoadTimelineService.class);
        context.stopService(intent2);
        Intent intent3 = new Intent(context, DownloadTimelineResService.class);
        context.stopService(intent3);
        Intent intent4 = new Intent(context, UploadTimelineService.class);
        context.stopService(intent4);
    }

    public static final String ACTION_EXTERNAL_OPEN_CREATE_STATE = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_OPEN_CREATE_STATE";

    public static final int EXTRA_OPEN_CREATE_STATE_READY = 0;

    public static final int EXTRA_OPEN_CREATE_STATE_START = 1;

    public static final int EXTRA_OPEN_CREATE_STATE_END = 2;

    public static final String EXTRA_CAN_BACK = "extra_can_back";

    public static final String ACTION_EXTERNAL_RESULT_QRCDOE = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_RESULT_QRCDOE";

    public static final String ACTION_EXTERNAL_RESULT_PHOTO = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_RESULT_PHOTO";

    /*请求编码*/

    public static final int REQUEST_OPEN_SCAN = 0;

    public static final int REQUEST_OPEN_CAMERA = 1;

    public static final int REQUEST_OPEN_PHOTO = 2;

    public static final int REQUEST_OPEN_BABY_INFO = 3;

    public static final int REQUEST_OPEN_TIMELINE_PHOTO = 4;

    public static final int REQUEST_OPEN_TIMELINE_CAMERA = 5;

    public static final int REQUEST_OPEN_TIMELINE_VIDEO = 6;

    public static final int REQUEST_OPEN_TIMELINE_MILESTONE = 7;
    public static final int ChangeBabySex = 8;
    public static final int ChangeBabyXuexing = 9;
    public static final int ChangeBabyname = 10;
    public static final int AddBabyname = 11;
    public static final int ChangeBabynoteName = 12;

    public static final int REQUEST_OPEN_BABY_DIARY = 13;

    public static final int REQUEST_ASK_PERMISSIONS = 14;

    /*同步服务发送广播*/

    /*广播内容*/

    public static final String ACTION_TOKEN_ERROR = "com.innovation.chengzhangriji.intent.action.ACTION_TOKEN_ERROR";

    /**
     * 更新数量
     */
    public static final String ACTION_EXTERNAL_UPDATE_NUMBER = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_UPDATE_NUMBER";

    /**
     * 剩余数量
     */
    public static final String ACTION_EXTERNAL_REMAIN_NUMBER = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_REMAIN_NUMBER";

    /**
     * 创建时间.
     */
    public static final String ACTION_EXTERNAL_CREATE_TS = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_CREATE_TS";

    /**
     * 信息
     */
    public static final String ACTION_EXTERNAL_MESSAGE = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_MESSAGE";

    /*同步*/

    /**
     * 同步开始
     */
    public static final String ACTION_SYNC_TIMELINE_START = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_START";

    /**
     * 同步成功
     */
    public static final String ACTION_SYNC_TIMELINE_SUCCESS = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_SUCCESS";

    /**
     * 同步失败
     */
    public static final String ACTION_SYNC_TIMELINE_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_FAILURE";

    /**
     * 同步令牌失败
     */
    public static final String ACTION_SYNC_TIMELINE_TOKEN_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_TOKEN_FAILURE";

    /*加载更多*/

    /**
     * 加载开始
     */
    public static final String ACTION_LOAD_TIMELINE_START = "com.innovation.chengzhangriji.intent.action.ACTION_LOAD_TIMELINE_START";

    /**
     * 加载成功
     */
    public static final String ACTION_LOAD_TIMELINE_SUCCESS = "com.innovation.chengzhangriji.intent.action.ACTION_LOAD_TIMELINE_SUCCESS";

    /**
     * 加载失败
     */
    public static final String ACTION_LOAD_TIMELINE_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_LOAD_TIMELINE_FAILURE";

    /**
     * 加载令牌失败
     */
    public static final String ACTION_LOAD_TIMELINE_TOKEN_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_LOAD_TIMELINE_TOKEN_FAILURE";

    /*网络连接不可用*/

    /**
     * 网络连接不可用
     */
    public static final String ACTION_NETWORK_UNAVAILABLE = "com.innovation.chengzhangriji.intent.action.ACTION_NETWORK_UNAVAILABLE";

    /**
     * 同步照片开始
     */
    public static final String ACTION_SYNC_TIMELINE_PHOTO_START = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_PHOTO_START";

    /**
     * 同步照片成功
     */
    public static final String ACTION_SYNC_TIMELINE_PHOTO_SUCCESS = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_PHOTO_SUCCESS";

    /**
     * 同步照片成功唯一标识
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_UUID = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_UUID";

    /**
     * 同步照片成功网络地址
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_URL = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_URL";

    /**
     * 同步照片成功本地缩略图地址
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_LOCAL_THUMB_URL = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_LOCAL_THUMB_URL";

    /**
     * 同步照片成功编号
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_NUMBER = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_SUCCESS_NUMBER";

    /**
     * 同步照片失败
     */
    public static final String ACTION_SYNC_TIMELINE_PHOTO_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_PHOTO_FAILURE";

    /**
     * 同步照片失败信息
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_FAILURE_MESSAGE = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_PHOTO_FAILURE_MESSAGE";

    /**
     * 同步音频开始
     */
    public static final String ACTION_SYNC_TIMELINE_AUDIO_START = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_AUDIO_START";

    /**
     * 同步音频成功
     */
    public static final String ACTION_SYNC_TIMELINE_AUDIO_SUCCESS = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_AUDIO_SUCCESS";

    /**
     * 同步音频成功唯一标识
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_SUCCESS_UUID = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_SUCCESS_UUID";

    /**
     * 同步音频成功网络地址
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_SUCCESS_URL = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_SUCCESS_URL";

    /**
     * 同步音频成功本地地址
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_SUCCESS_LOCAL_URL = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_SUCCESS_LOCAL_URL";

    /**
     * 同步音频失败
     */
    public static final String ACTION_SYNC_TIMELINE_AUDIO_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_AUDIO_FAILURE";

    /**
     * 同步音频失败信息
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_FAILURE_MESSAGE = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_AUDIO_FAILURE_MESSAGE";

    /**
     * 同步视频截图开始
     */
    public static final String ACTION_SYNC_TIMELINE_VIDEO_SCREENSHOT_START = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_VIDEO_SCREENSHOT_START";

    /**
     * 同步视频截图成功
     */
    public static final String ACTION_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS";

    /**
     * 同步视频截图成功唯一标识
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS_UUID = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS_UUID";

    /**
     * 同步视频截图成功网络地址
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS_URL = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS_URL";

    /**
     * 同步视频截图成功本地地址
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS_LOCAL_URL = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_SUCCESS_LOCAL_URL";

    /**
     * 同步视频截图失败
     */
    public static final String ACTION_SYNC_TIMELINE_VIDEO_SCREENSHOT_FAILURE = "com.innovation.chengzhangriji.intent.action.ACTION_SYNC_TIMELINE_VIDEO_SCREENSHOT_FAILURE";

    /**
     * 同步视频截图失败信息
     */
    public static final String ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_FAILURE_MESSAGE = "com.innovation.chengzhangriji.intent.action.ACTION_EXTERNAL_SYNC_TIMELINE_VIDEO_SCREENSHOT_FAILURE_MESSAGE";

    /**
     * 收到新评论，下载成功后，通知
     */
    public static final String ACTION_NEW_COMMENT_DOWNLOAD_SUCCEED = "com.innovation.chengzhangriji.intent.action.ACTION_NEW_COMMENT_DOWNLOAD_SUCCEED";

    //---------------------------------------------//

    /**
     * 音频最大长度
     */
    public static final int AUDIO_MAX_LENGTH = 60;

    /**
     * 视频最大长度
     */
    public static final int VIDEO_MAX_LENGTH = 20;

    /**
     * 缩略照片文件夹路径
     */
    public static final String THUMB_PHOTO_DIR = "/thumb_photos";

    /**
     * 照片文件夹路径
     */
    public static final String PHOTO_DIR = "/photos";

    /**
     * 音频文件夹路径
     */
    public static final String AUDIO_DIR = "/audios";

    /**
     * 截图文件夹路径
     */
    public static final String SCREENSHOT_DIR = "/screenshots";

    /**
     * 视频文件夹路径
     */
    public static final String VIDEO_DIR = "/videos";

    /**
     * 生成固定尺寸的图片地址
     *
     * @param url  图片地址
     * @param size 100 480 640 800 1024 1280 1920
     * @return 固定尺寸的图片地址
     */
    public static String createSizeUrl(String url, int size) {
        String sizeUrl = "/" + size + "/";
        int endIndex = url.lastIndexOf('/');
        String end = url.substring(endIndex + 1, url.length());
        return url.substring(0, endIndex) + sizeUrl + end;
    }

    /**
     * 生成文件
     *
     * @param context 上下文
     * @param typeDir {@link #THUMB_PHOTO_DIR}
     *                {@link #PHOTO_DIR}
     *                {@link #AUDIO_DIR}
     *                {@link #SCREENSHOT_DIR}
     *                {@link #VIDEO_DIR}
     * @return 文件
     */
    public static File createFile(Context context, String typeDir) {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.CHINA).format(new Date());
        File dir = new File(context.getFilesDir().getPath() + typeDir);
        //noinspection ResultOfMethodCallIgnored
        dir.mkdir();
        return new File(dir, timeStamp);
    }

    /**
     * 获取指定目录
     * @param context
     * @param typeDir
     * @return
     */
    public static File getDir(Context context, String typeDir) {
        File dir = new File(context.getFilesDir().getPath() + typeDir);
        if(!dir.exists()) {
            dir.mkdirs();
        }
        return dir;
    }

    /**
     * 获取配置文件的路径
     * @param context
     * @return
     */
    public static File getAppConfig(Context context) {
        File appConfig = new File(context.getFilesDir().getPath() + "/config/");
        if(!appConfig.exists()) {
            appConfig.mkdirs();
        }
        return new File(appConfig, CONFIG_FILE_NAME);
    }

    /**
     * 加载配置文件
     * @param context
     */
    public static void loadConfig(Context context) {
        ConfigurationManager.getInstance().loadConfig(context);
    }

    /**
     * 生成文件
     *
     * @return 文件
     */
    public static File createPicture() {
        if (!isExternalStorageWritable()) {
            return null;
        }
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.CHINA).format(new Date()) + ".jpg";
        File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath());
        //noinspection ResultOfMethodCallIgnored
        dir.mkdir();
        File privateDir = new File(dir.getPath() + "/CHZHRJ");
        //noinspection ResultOfMethodCallIgnored
        privateDir.mkdir();
        return new File(privateDir, timeStamp);
    }

    /* Checks if external storage is available for read and write */
    private static boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        return Environment.MEDIA_MOUNTED.equals(state);
    }

    /*旧的方法*/
    public static final int[] EMOJIS = {
            R.string.emoji_01,
            R.string.emoji_02,
            R.string.emoji_03,
            R.string.emoji_04,
            R.string.emoji_05,
    };

    public static final int[] EMOJIS_P = {
            R.string.emoji_01_p,
            R.string.emoji_02_p,
            R.string.emoji_03_p,
            R.string.emoji_04_p,
            R.string.emoji_05_p,
    };

    public static final int[] EMOJIS_DRAWABLE = {
            R.drawable.ic_emoji_1,
            R.drawable.ic_emoji_2,
            R.drawable.ic_emoji_3,
            R.drawable.ic_emoji_4,
            R.drawable.ic_emoji_5,
    };

    // TODO 临时
    public static final int EMOJI_QRCODE_DRAWABLE = R.drawable.ic_emoji_qrcode;

    public static final int FUNCTION_PHOTO = 0;
    public static final int FUNCTION_CAMERA = 1;
    public static final int FUNCTION_VIDEO = 2;
    public static final int FUNCTION_FIRST = 3;

    public static final int[] FUNCTION_DRAWABLE = {
            R.mipmap.btn_bottom_function_1,
            R.mipmap.btn_bottom_function_2,
            R.mipmap.btn_bottom_function_3,
            R.mipmap.btn_bottom_function_4,
    };

    private static DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.ic_head_circle_default_small)    //在ImageView加载过程中显示图片
            .showImageForEmptyUri(R.drawable.ic_head_circle_default_small)  //image连接地址为空时
            .showImageOnFail(R.drawable.ic_head_circle_default_small)   //image加载失败
            .cacheOnDisk(true)  //加载图片时会在磁盘中加载缓存
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();

    private static DisplayImageOptions optionsHead = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.ic_head_circle_default_small)    //在ImageView加载过程中显示图片
            .showImageForEmptyUri(R.drawable.ic_head_circle_default_small)  //image连接地址为空时
            .showImageOnFail(R.drawable.ic_head_circle_default_small)   //image加载失败
            .cacheOnDisk(true)  //加载图片时会在磁盘中加载缓存
            .cacheInMemory(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();

    private static DisplayImageOptions optionsHeadUnKnown = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.mipmap.baby_head_unknown)    //在ImageView加载过程中显示图片
            .showImageForEmptyUri(R.mipmap.baby_head_unknown)  //image连接地址为空时
            .showImageOnFail(R.mipmap.baby_head_unknown)   //image加载失败
            .cacheOnDisk(true)  //加载图片时会在磁盘中加载缓存
            .cacheInMemory(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();

    private static DisplayImageOptions optionsHeadUnKnown_Exists = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.mipmap.baby_head_unknown)  //image连接地址为空时
            .showImageOnFail(R.mipmap.baby_head_unknown)   //image加载失败
            .cacheOnDisk(true)  //加载图片时会在磁盘中加载缓存
            .cacheInMemory(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();

    private static DisplayImageOptions optionsPhoto = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.ic_photo_empty)    // 在ImageView加载过程中显示图片
            .showImageForEmptyUri(R.drawable.ic_photo_empty)  // image连接地址为空时
            .cacheOnDisk(true)                                // 加载图片时会在磁盘中加载缓存
            .cacheInMemory(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();

    private static DisplayImageOptions optionsGallery = new DisplayImageOptions.Builder()
            .cacheOnDisk(true)  //加载图片时会在磁盘中加载缓存
            .build();

    public static DisplayImageOptions getOptions() {
        return options;
    }

    public static DisplayImageOptions getOptionsHead() {
        return optionsHead;
    }

    public static DisplayImageOptions getOptionsHeadUnKnown() {
        return optionsHeadUnKnown;
    }

    public static DisplayImageOptions getOptionsHeadUnKnown_Exists() {
        return optionsHeadUnKnown_Exists;
    }

    public static DisplayImageOptions getOptionsPhoto() {
        return optionsPhoto;
    }

    public static DisplayImageOptions getOptionsGallery() {
        return optionsGallery;
    }
}
